// pages/message/message.js
import config from "../../../api/config";
const mixins = require('../../../mixins/message')
const common = require('../../../mixins/common')
var a, e, app = getApp();
let interstitialAd = null;
const options = {

  /**
   * 页面的初始数据
   */
  data: {
    messageLists:[],
    advert:app.globalData.advert,
    currentConfig: {
      show: false,
      transition: true,
      zIndex: 99,
      locked: false,
      direction: 'bottom',
      arcRadius: 18,
      maxHeight: 600,
      minHeight: 600,
      opacity: 0.4
    },
    ismessage:true,
    menus: [
   
      {
        icon: "/image/message_icon_area_like.png",
        text: "点赞",
        num: 0,
        url: "/pages/message/like/like"
      }, 
      {
        icon: "/image/message_icon_area_comment.png",
        text: "评论",
        num: 0,
        url: "/pages/message/comment/comment"
      }, 
      {
      icon: "/image/message_icon_area_question.png",
      text: "收藏",
      num: 0,
      url: "/pages/message/fav/fav"
    }, 
    
    
  
  ],
    page: 1,
    ad:config.gridAd,
    messageList: [],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    if (wx.createInterstitialAd&&this.data.advert.interstitialAd) {
      interstitialAd = wx.createInterstitialAd({
        adUnitId: this.data.advert.interstitialAd
      })
      interstitialAd.onLoad(() => {})
      interstitialAd.onError((err) => {})
      interstitialAd.onClose(() => {})
    }

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    if (interstitialAd) {
      interstitialAd.show().catch((err) => {
        console.error(err)
      })
    }
  },

  onMenuItem: function (e) {
    var url = e.currentTarget.dataset.url;
     wx.navigateTo({
       url: url,
     })
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    "function" == typeof this.getTabBar && this.getTabBar() && this.getTabBar().setData({
      selected: 3
  })
    let user = app.globalData.user
    if (!user) {
      wx.showToast({
        title: '未登录,请登录',
      })
      wx.navigateTo({
        url: '/pages/login/login',
      })
    }
    this.setData({
      user: user,
    })
    this.getMessages({
      type: 'private',
      page: this.data.page,
    });
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    this.setData({
      messageList: [],
      page: 1,
      isLastPage:false,
    })
    this.getMessages({
      type: 'private',
      page: this.data.page,
    })
    wx.stopPullDownRefresh({
      success: (res) => {},
    })
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
   if(!this.data.isLastPage){
    this.getMessages({
      type: 'private',
      page: this.data.page,
    })
   }
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
}


mixins(options)
common(options)
Page(options)